﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace hpm
{
    class Utility
    {
        DAL da = new DAL();
        SqlCommand slqcom;

        public Utility()
        {
        }

        public string getNgayHientai()
        {
            da.ketnoiServer();
            this.slqcom = new SqlCommand();
            this.slqcom.CommandText = "select getdate() as NgayHientai";
            this.slqcom.Connection = da.con;
            SqlDataReader reader = slqcom.ExecuteReader();
            reader.Read();
            string strNgayHienTai = reader[0].ToString();
            da.da_closeConnect();
            return strNgayHienTai;
        }

        public void addNewRowToGridControl(DevExpress.XtraGrid.Views.Grid.GridView grvObj, string strCompaire, string[] cCompaires)
        {
            if (Array.IndexOf(cCompaires, strCompaire) > -1)
            {
                grvObj.AddNewRow();
                grvObj.FocusedRowHandle = grvObj.DataRowCount - 1;
                grvObj.FocusedColumn = grvObj.VisibleColumns[0];
            }
        }

        public void addCaptionToGridView(DevExpress.XtraGrid.Views.Grid.GridView grvObj, string[] captionArr)
        {
            for(var i = 0; i < captionArr.Length; i++)
            {
                grvObj.Columns[i].Caption = captionArr[i];
            }
        }

        public void addCaptionToGridView(DevExpress.XtraGrid.GridControl grdObj, DevExpress.XtraGrid.Views.Grid.GridView grvObj, DataTable dttbale, string[] captionArr)
        {
            grvObj.Columns.Clear();
            grdObj.DataSource = dttbale;
            for (var i = 0; i < captionArr.Length; i++)
            {
                grvObj.Columns[i].Caption = captionArr[i];
            }

            grvObj.AddNewRow();
        }

    }
}
